<template>
    <div class="divBox">
        <el-card class="p20">
            <div class="searchBox">
                <oaFromBox
                    v-if="search.length > 0"
                    :isAddBtn="false"
                    :isViewSearch="false"
                    :search="search"
                    :title="headertitle"
                    :total="total"
                    @confirmData="confirmData"
                ></oaFromBox>
                <div style="position: absolute;right:30px;top:30px;" v-if="keyName=='xiaoshoumingxi'">
                    <el-button icon="el-icon-circle-plus-outline" size="mini" type="success" @click="SaveBomindexData">保存</el-button>
                    <el-button icon="el-icon-finished" size="mini" type="danger" @click="saveboxOrder">生成生产单</el-button>
                </div>
            </div>
            <div class="p10">
                <div class="table-box" v-loading="loading">
                    <div class="table-container" v-if="showFieldData.length > 0">
                        <el-table ref="table" :data="tableData" :max-height="tableHeight" class="draggable-table" 
                        @row-click="handleRowClick" @selection-change="handleSelectionChange" @row-dblclick="handleRowDblClick">  
                            <el-table-column type="selection" align="center" width="50" fixed="left"> </el-table-column>
                            <!-- <el-table-column prop="id" align="center" width="50"> </el-table-column> -->
                            <el-table-column prop="" :label="item.field_name" v-for="(item,indexs) in showFieldData" :key="indexs" 
                              :min-width="handelrWidth(item)">
                                 <template slot-scope="scope">
                                     <div v-if="keyName=='wuliaoxinxi'">
                                        <div v-if="item.association_crud_id">
                                           {{ handleraccociation(scope.row[item.field_name_en], item.field_name_en) }}
                                        </div>
                                        <div v-else>
                                            {{ handlerValue(scope.row[item.field_name_en]) }}
                                        </div>
                                     </div>
                                     <div v-else-if="keyName == 'shengchandan'">
                                        <!-- <div v-if="item.association_crud_id">
                                            AAA{{ item.association_crud_id }}/{{ item.form_value }}/{{ item.field_name_en }}
                                           {{ handleraccociation(scope.row[item.field_name_en], item.field_name_en) }}
                                        </div> -->
                                        <div>
                                            {{ handlerValue(scope.row[item.field_name_en]) }}
                                        </div>
                                     </div>
                                     <div v-else>
                                        <div v-if="item.data_dict_id">
                                            <div v-if="handlerDisabel(item.field_name_en)">
                                                {{ handlerDisabelval(scope.row[item.field_name_en], item.field_name_en) }}
                                            </div>
                                            <div v-else>
                                                <div v-if="zidiangData[item.field_name_en] && zidiangData[item.field_name_en].length > 0">
                                                    <el-select v-model="scope.row[item.field_name_en]" placeholder="请选择" :disabled="scope.row[item.disabled]">
                                                        <el-option
                                                            v-for="item in zidiangData[item.field_name_en]"
                                                            :key="item.id"
                                                            :label="item.name"
                                                            :value="item.value">
                                                        </el-option>
                                                    </el-select>
                                                </div>
                                            </div>
                                            
                                        </div>
                                        <div v-else-if="item.association_crud_id">
                                            <div v-if="zidiangData[item.field_name_en] && zidiangData[item.field_name_en].length > 0">
                                                <el-select v-model="scope.row[item.field_name_en]" placeholder="请选择" :disabled="scope.row[item.disabled]" >
                                                    <el-option
                                                        v-for="item in zidiangData[item.field_name_en]"
                                                        :key="item.id"
                                                        :label="item.zhongwenmiaoshu"
                                                        :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </div>
                                        </div>
                                        <div v-else>
                                            <div v-if="item.field_name_en=='mianfeishu'">
                                                <el-input type="number" v-model="scope.row[item.field_name_en]" @change="handlerMoneyjs($event,scope.$index, scope.row)"></el-input>
                                            </div>
                                            <div v-else>
                                                {{ handlerValue(scope.row[item.field_name_en]) }}
                                            </div>
                                            
                                        </div>
                                    </div>
                                 </template>
                            </el-table-column>
                            <el-table-column fixed="right" label="操作" width="100" align="center" v-if="keyName !='xiaoshoumingxi'">
                                <template slot-scope="scope">
                                    <el-button size="small" type="text" @click.stop="onCheck(scope.row)">查看</el-button>
                                </template>
                            </el-table-column>
                            <!-- <el-table-column fixed="right" label="操作" width="100" align="center" v-else>
                                <template slot-scope="scope">
                                    <el-utton type="text" @click.stop="editRow(scope.row, 2)">编辑</el-utton>
                                </template>
                            </el-table-column> -->
                        </el-table>
                    </div>
                    <div style="height:48px;position: relative;">
                        <div class="page-fixed" style="bottom:0;">
                            <el-pagination :page-size="formData.limit" :current-page="formData.page"
                                :page-sizes="[15, 20, 30, 50, 100]" layout="total,sizes, prev, pager, next, jumper"
                                :total="total" @current-change="pageChange" @size-change="handleSizeChange" />
                        </div>
                    </div>
                </div>
            </div>
        </el-card>
        <div class="" style="margin-top:20px;">
            <!-- <box ref="wlqdtabel" v-if="wlqdtabelShownew" :id="boxid" ></box> -->
            <wuliaoqingdan ref="wlqdtabel" v-if="wlqdtabelShownew" :id="boxid" :pagestatus="pagestatus" :zidianbaseData="zidianbaseData" @changeBom="changeBom"></wuliaoqingdan>
        </div>
        <!-- 新增(新) -->
        <add-drawernew v-if="addDrawerShownew" ref="addDrawernew" :keyName="keyName" @getList="getList"></add-drawernew>
    </div>
</template>

<script>
import {
    crudModuleListApi,
    crudModuleInfoApi,
    crudJoinListApi,
    databaseInfoApi,
    crudModuleUpdateApi,
    crudModuleFindApi,
    putUpdateFieldApi,
} from '@/api/develop'
import { getMrpAddProductApi } from '@/api/other'
import { getDictDatainfoApi, getDictDataListApi } from '@/api/form'
import draggable from 'vuedraggable';
import Sortable from 'sortablejs'
import oaFromBox from '@/components/common/oaFromBox'
import box from './components/box'
import wuliaoqingdan from './components/wuliaoqingdan.vue';
import addDrawernew from './components/addDrawernew'
export default {
    name: 'boxList',
    components: {
      oaFromBox, box, draggable, wuliaoqingdan, addDrawernew
    },
    data() {
        return {
            tableData: [],
            loading: true,
            total: 0,
            wlqdtabelShownew: false,
            formData: { // 查询物料档案信息接口查询条件
                page: 1,
                limit: 15,
                source: [['M'],['C'],['X']],
                is_system: 1,
                order_by: {},
                scope_frame: 'all',
                show_search_type: '0',
                view_search: [],
                view_search_boolean: '',
                
            },
            formszgxData: { // 查询工序设置接口查询条件
                page: 1,
                limit: 100,
                is_system: 1,
                is_field_all:'',
                order_by: {},
                scope_frame: 'all',
                show_search_type: '0',
                view_search: [],
                view_search_boolean: '',
                gongxushezhifuxuan: [["1"]]
            },
            publicSearch: { // 公共查询条件
                page: 1,
                limit: 15,
                is_system: 1,
                is_field_all:'',
                order_by: {},
                scope_frame: 'all',
                show_search_type: '0',
                view_search: [],
                view_search_boolean: '',
            },
            searchdata: [ // 物料清单顶部搜索
                {
                    field_name: '物料编码',
                    field_name_en: 'item_sn',
                    form_value: 'input'
                },
                {
                    field_name: '物料中文描述',
                    field_name_en: 'item_depc',
                    form_value: 'input',
                }
            ],
            scSearchData: [
               {
                    field_name: '生产单号',
                    field_name_en: 'shengchandanhao',
                    form_value: 'input'
                },
                {
                    field_name: '客号',
                    field_name_en: 'kehao',
                    form_value: 'input',
                },
                {
                    field_name: 'kepo',
                    field_name_en: 'kepo',
                    form_value: 'input'
                },
                {
                    field_name: '客款号',
                    field_name_en: 'kekuanhao',
                    form_value: 'input',
                }
            ],
            search: [], // 当前列表顶部的搜索查询参数数组
            draggingRow: null,
            dragOptions: {
                animation: 150,
                handle: '.drag-handle',
                ghostClass: 'ghost'
            },
            boxid:0,
            pagestatus: 2,
            keyName: '',
            searchForm: {}, // 最后当前查询条件
            allSearchForm: {
                page: 1,
                limit: 15,
                table: '',
                data: ''
            },
            showFieldData: [],
            zidiangData: null,
            dictForm: { // 字典数据
                types: '',
                level: 1,
                pid:''
            },
            selectTableRow: [],
            baseindex: 0,
            zidianbaseData:{
                peijianleixing:[],
                gongxushezi:[]
            },
            headertitle:'物料清单',
            startshowfields: [],
            addDrawerShownew: false,
        }
    },

  
    created() {
        
        
    },
    mounted() {
        const routeString = this.$route.path
        const routeArray = routeString.split('/').filter((item) => item !== '')
        this.keyName = routeArray[3]
        console.log("keyName ", this.keyName)
        if(this.keyName == 'xiaoshoumingxi'){ // 订单评审(销售明细)
            this.headertitle = '订单评审'  
            this.baseindex = 1;   
            let formdatas = {
                joins: [
                    {
                        type: "leftJoin",
                        table: "xiaoshoudingdan",
                        alias: "d",
                        on: [
                            [
                                "m.xiaoshoudingdanid",
                                "d.id"
                            ]
                        ]
                    },
                    {
                        type: "leftJoin",
                        table: "wuliaoxinxi",
                        alias: "x",
                        on: [
                            [
                                "m.wuliaodanganid",
                                "x.id"
                            ]
                        ]
                    }
                ],
                conditions: {
                     'm.pihe': 1,  
                     'm.pingshenzhuangtai': 0    
                },
                fields: [
                    "m.*",
                    "d.id as did",
                    "x.item_sn as item_sn",
                    "d.gongsidaima as gongsidaima",
                    "d.danjuleixing as danjuleixing",
                    "d.kehao as dkehao",
                    "d.kehaomingcheng as kehaomingcheng",
                    "x.bomm_ap_flag as bomm_ap_flag",
                    'x.pdl as pdl',
                    'x.source as source'

                ],
                order: {
                    "m.id": "desc"
                }
            }
            this.allSearchForm.table = this.keyName +' as ' + 'm',
            this.allSearchForm.data = encodeURI(JSON.stringify(formdatas))
            this.searchForm = this.allSearchForm;
            let searchdata = [
                {
                    field_name: '客号',
                    field_name_en: 'kehaomingcheng',
                    form_value: 'input'
                },
                {
                    field_name: '销售单号',
                    field_name_en: 'xiaoshoudanhao',
                    form_value: 'input'
                },
                {
                    field_name: '客PO',
                    field_name_en: 'kepo',
                    form_value: 'input'
                },
                {
                    field_name: '物料编码',
                    field_name_en: 'item_sn',
                    form_value: 'input'
                },
            ]
            this.search = JSON.parse(JSON.stringify(searchdata));
            console.log("this", this.search)
            this.getList(this.searchForm);
        }else if(this.keyName == 'shengchandan'){ // 生成单
            console.log("abd")
            this.baseindex = 2;
            this.searchForm = this.publicSearch;
            this.searchForm.kehao = '';
            this.searchForm.shengchandanhao = '';
            this.searchForm.kekuanhao = '';
            this.searchForm.kepo = ''
            this.search = JSON.parse(JSON.stringify(this.scSearchData));
            console.log("dings", this.searchForm)
            this.getList(this.searchForm)
        }else{ // 物料清单
            this.headertitle = '物料清单'  
            this.handlerwlqdZidian();
            this.baseindex = 0;
            this.searchForm = this.formData
            this.searchForm.item_depc = '',
            this.searchForm.item_sn = '',
            this.search = JSON.parse(JSON.stringify(this.searchdata));
            this.getList(this.searchForm)
        }
    },
    methods: {
        // 更新保存
        async SaveBomindexData(){
           if(this.selectTableRow.length > 0){
               let showformdata = this.startshowfields;
               let formdata = this.selectTableRow[0];
               let id = this.selectTableRow[0].id;
               let result = await crudModuleFindApi(this.keyName, id)
               let mdinfo = result.data.module_info;
               const mergedData = Object.assign({}, mdinfo, formdata);
               this.handlerSaveUpdate(showformdata, mergedData, id)
           }else{
             this.$message.error("请选择一行要保存的数据！")
           }
        },
        // 修改保存方法
        async handlerSaveUpdate(showformdata,formdata, id){
            let objs = {}
               for(let i=0;i < showformdata.length;i++){
                  if(showformdata[i].field_name_en == 'shengchanxian'){
                    objs[showformdata[i].field_name_en] = this.handlerbaseValobj(formdata[showformdata[i].field_name_en],this.zidiangData[showformdata[i].field_name_en])
                  }else{
                    if(this.zidiangData[showformdata[i].field_name_en]){
                        objs[showformdata[i].field_name_en] = this.handlerReplacexieganVal(formdata[showformdata[i].field_name_en],this.zidiangData[showformdata[i].field_name_en])
                    }else{
                       objs[showformdata[i].field_name_en] = this.handlerfilterk(formdata[showformdata[i].field_name_en])
                    }
                  }
               }
               objs.pihe = formdata.pihe;
               objs.xiaoshoudingdanid = formdata.xiaoshoudingdanid;
               objs.wuliaodanganid = formdata.wuliaodanganid;
               objs.wuliaobianma = {id: formdata.wuliaodanganid, name: formdata.wuliaobianma.name || ''};
               let result = await crudModuleUpdateApi(this.keyName, id, objs, true)
               if(result.status==200){
                  this.$message.success("保存成功")
                  this.confirmData('reset')
               }else{
                  this.$message.error("保存失败")
               }
        },
        // 生成生产单
        async saveboxOrder(){
            if(this.selectTableRow.length > 0){
                let ids = []
                let tabselectRow = this.selectTableRow;
                for(let i=0;i<tabselectRow.length;i++){
                    if(tabselectRow[i].pihe == 1){
                       ids.push(tabselectRow[i].id)
                    }
                }
                let results = await getMrpAddProductApi({id: JSON.stringify(ids) })
                if(results.status == 200){
                    this.$message.success(results.message)
                    await putUpdateFieldApi(this.keyName, tabselectRow[0].id, { field_name: 'pingshenzhuangtai', value: 1 }, true)
                    this.getList(this.searchForm)
                }
            }else{
               this.$message.error("请选择一行要生成生产单的数据！")
            }

        },
        // 生成订单后订单评审状态改变
        
        handleSelectionChange(val) {
            if(val.length > 0){
                this.selectTableRow = val;
            }else{
                this.selectTableRow = []
            }
        },
        async handlerwlqdZidian(){
           let result =await getDictDataListApi({types: 'peijianleixing', level: 1, pid: ''}) // 配件类型字段
           this.zidianbaseData.peijianleixing = result.data.list;
           let result2 = await crudModuleListApi('gongxushezhong', this.formszgxData) // 工序设置实体表
           this.zidianbaseData.gongxushezi = result2.data.list;
        },
        // 获取物料清单列表
        async getList(formData) {
            if(this.baseindex== 1){ // 订单评审数据(订单明细表)
                this.handlerOrderPingshen(formData);
            }else if(this.baseindex== 2){
               this.handlerShengchanOrder(formData);
            }else{ // 物料清单数据(物料档案表)
                this.handlerWLQDbom(formData);
            } 
        },
        // 订单评审列表数据
        async handlerOrderPingshen(formData){ 
            let resdata = await crudModuleInfoApi(this.keyName, 151)
            let showfields = resdata.data.showField;
            this.startshowfields = JSON.parse(JSON.stringify(showfields));
            let showlist=['guanlian', 'peijian', 'wuliaobianma','danjia','jine', 'pinpai', 'yewuchangqi', 'paikuanriqi', 'yewuchangqi', 'qiliaoriqi',
                'beizhu', 'keqi', 'pihe', 'pingshenzhuangtai', 'piheren', 'piheshijian', 'kepoxuhao']
            let obj = { field_name_en: 'item_sn', field_name: '物料编码'}
            let objs = {},kpoobj = {}, kpoobj1 = {};
            let showFieldList = [];
            showfields.unshift({field_name_en: 'kehaomingcheng', field_name: '客号', form_value :'input'})
            showfields.unshift({field_name_en: 'gongsidaima', field_name: '公司代码', data_dict_id : 70})
            showfields.push({field_name_en: 'bomm_ap_flag', field_name: 'BOM批核', data_dict_id : 0})
            showfields.splice(5, 0, {field_name_en: 'danjuleixing', field_name: '单据类型', data_dict_id : 124})
            showfields.splice(6, 0, {field_name_en: 'item_sn', field_name: '物料编码', form_value:'input'}); // 物料编码
            for(let i=0;i<showfields.length;i++){
                if(!showlist.includes(showfields[i].field_name_en)){
                    if(showfields[i].field_name_en=='kepo'){
                        kpoobj = JSON.parse(JSON.stringify(showfields[i]));
                        showfields.splice(i, 1);
                    }else{
                        if(!this.zidiangData){
                            if(showfields[i].data_dict_id){
                                let dataictnamearr = []
                                let datadict = await getDictDatainfoApi(showfields[i].data_dict_id);
                                dataictnamearr.push(datadict.data.ident);
                                this.dictForm.types = dataictnamearr;
                                let datadictDta = await getDictDataListApi(this.dictForm)
                                objs[showfields[i].field_name_en] = datadictDta.data.list;
                            }
                            if(showfields[i].association_crud_id && showfields[i].field_name_en != 'wuliaobianma' ){
                                let database = await databaseInfoApi(showfields[i].association_crud_id)
                                let tabbasename = database.data.table_name_en;
                                let datalist = await crudModuleListApi(tabbasename, {page: 1, limit: 50});
                                objs[showfields[i].field_name_en] = datalist.data.list;
                            }
                        }
                        showFieldList.push(showfields[i])
                    }
                }
            }
            if(JSON.stringify(objs) !='{}'){
                this.zidiangData = objs;
            }
            showFieldList.splice(2, 0, kpoobj)
            this.showFieldData = showFieldList;
            let resultCrud = await crudJoinListApi(formData)
            let resultdata = resultCrud.data.list;
            resultdata.map((item)=>{
                item.shengchanshu = Number(item.shuliang) + Number(item.mianfeishu);
                item.laiyuan = this.handlerReplacexiegan(item.laiyuan, 'laiyuan')
                item.zhuangtai = this.handlerReplacexiegan(item.zhuangtai, 'zhuangtai')
                item.danwei = this.handlerReplacexiegan(item.danwei, 'danwei')
                item.danjuleixing = this.handlerReplacexiegan(item.danjuleixing, 'danjuleixing')
                item.gongsidaima = this.handlerReplacexiegan(item.gongsidaima, 'gongsidaima')
            })
            this.total = resultCrud.data.count;
            this.tableData = resultdata;
            this.loading = false;
        },
        // 物料清单列表数据
        async handlerWLQDbom(formData){
            let resdata = await crudModuleInfoApi(this.keyName, 52)
            let showlistfield = resdata.data.showField;
            this.startshowfields = showlistfield;
            let showlist = ['item_sn', 'item_depc','itemt_sn', 'unit','source', 'bomm_ver','bomm_ap_flag', 'bomm_ap_user','date_time_picker']
            let showFieldData = [],objs = {};
            for(let i=0;i<showlistfield.length;i++){
                if(showlist.includes(showlistfield[i].field_name_en)){
                    showFieldData.push(showlistfield[i])
                    if(!this.zidiangData){
                        if(showlistfield[i].association_crud_id && showlistfield[i].field_name_en != 'wuliaobianma' ){
                            let database = await databaseInfoApi(showlistfield[i].association_crud_id)
                            let tabbasename = database.data.table_name_en;
                            let datalist = await crudModuleListApi(tabbasename, {page: 1, limit: 200});
                            objs[showlistfield[i].field_name_en] = datalist.data.list;
                        }
                    }
                }
            }
            if(JSON.stringify(objs) !='{}'){
                this.zidiangData = objs;
            }
            this.showFieldData = showFieldData;
            let resultCrud = await crudModuleListApi(this.keyName, formData);
            this.total = resultCrud.data.count;
            this.tableData = resultCrud.data.list;
            this.loading = false;
                
        },
        // 生产订单列表数据
        async handlerShengchanOrder(formData){
            let resdata = await crudModuleInfoApi(this.keyName, 21)
            console.log("resdata", resdata)
            let showlistfield = resdata.data.showField;
            let showlist = ['kehao']
            let showFieldData = [],objs = {};
            for(let i=0;i<showlistfield.length;i++){
                if(showlist.includes(showlistfield[i].field_name_en)){
                    if(!this.zidiangData){
                        if(showlistfield[i].association_crud_id){
                            let database = await databaseInfoApi(showlistfield[i].association_crud_id)
                            let tabbasename = database.data.table_name_en;
                            let datalist = await crudModuleListApi(tabbasename, {page: 1, limit: 200});
                            objs[showlistfield[i].field_name_en] = datalist.data.list;
                        }
                    }
                }
            }
            if(JSON.stringify(objs) !='{}'){
                this.zidiangData = objs;
            }
            this.showFieldData = showlistfield;
            let resultCrud = await crudModuleListApi(this.keyName, formData);
            console.log(resultCrud);
            this.total = resultCrud.data.count;
            this.tableData = resultCrud.data.list;
            this.loading = false;
        },

        changeBom(status){
            console.log("status", status)
            if(status == 13){ // 反批核返回
                this.getList(this.searchForm);
            }
        },
        async onSubmit() {
            let data = this.searchForm
            this.getList(data)
        },
        // 分页
        pageChange(e) {
            this.searchForm.page = e
            this.getList(this.searchForm)
        },
        // 设置每页条数
        handleSizeChange(e) {
            this.searchForm.limit = e
            this.getList(this.searchForm)
        },
        confirmData(data) {
            console.log("datasss", data)
            this.loading = true;
            if (data == 'reset') {
                this.searchForm.order_by = {}
                if(this.keyName == 'xiaoshoumingxi'){
                    this.allSearchForm.page = 1;
                    this.allSearchForm.limit = 15;
                    this.searchForm = this.allSearchForm;
                    this.loading = false;
                }else{
                    this.formData= {
                        page: 1,
                        limit: 15,
                        is_field_all: '',
                        is_system: 1,
                        order_by: {},
                        scope_frame: 'all',
                        show_search_type: '0',
                        view_search: [],
                        view_search_boolean: ''
                    }
                    this.searchForm = this.formData;
                    if(this.keyName=='wuliaixixi'){
                       this.searchForm.item_sn = '';
                    this.searchForm.item_depc = '';
                    }else{
                        this.searchForm.kehao = '';
                        this.searchForm.shengchandanhao = '';
                        this.searchForm.kekuanhao = '';
                        this.searchForm.kepo = ''
                    }
                }
                this.getList(this.searchForm)
            } else {
                if(data.sort_value){
                    if(data.sort_field){
                        this.searchForm.order_by[data.sort_field] = data.sort_value == 'desc'?'0': '1';
                    }
                }else{
                    this.searchForm.order_by = {}
                }
                if(this.keyName == 'xiaoshoumingxi'){ // 订单评审搜索(销售明细)
                   let formdata = JSON.parse(decodeURI(this.allSearchForm.data))
                   if(data.kehaomingcheng){ // 客户名称
                     formdata.conditions['d.kehaomingcheng'] = data.kehaomingcheng;
                   }else{
                      delete formdata.conditions['d.kehaomingcheng'];
                   }
                   if(data.kepo){ // 客PO
                     formdata.conditions['m.kepo'] = data.kepo;
                   }else{
                      delete formdata.conditions['m.kepo'];
                   }
                   if(data.item_sn){ // 物料编码
                      formdata.conditions['m.item_sn'] = data.item_sn;
                   }else{
                      delete formdata.conditions['m.item_sn'];
                   }
                   if(data.xiaoshoudanhao){ // 销售单号
                      formdata.conditions['d.xiaoshoudanhao'] = data.xiaoshoudanhao;
                   }else{
                      delete formdata.conditions['m.xiaoshoudanhao'];
                   }
                   this.allSearchForm.data = encodeURI(JSON.stringify(formdata))
                   this.searchForm = this.allSearchForm;
                  
                }else if(this.keyName=='wuliaoxinxi'){ // 物料清单
                    this.searchForm.item_sn = data.item_sn || ''
                    this.searchForm.item_depc = data.item_depc || ''
                }else if(this.keyName == 'shengchandan'){ // 生产单
                    console.log("AAdata", data)
                    this.searchForm.kehao = data.kehao ? this.handleraccociation(data.kehao, 'kehao') : '';
                    this.searchForm.shengchandanhao = data.shengchandanhao ? data.shengchandanhao: '';
                    this.searchForm.kekuanhao = data.kekuanhao? data.kekuanhao: '';
                    this.searchForm.kepo = data.kepo? data.kepo: '';

                }
                console.log(this.searchForm);
                this.getList(this.searchForm)
            }
        },
        // 单点击行显示
        async handleRowClick(row){
            this.boxid = row.id;
            // if(this.keyName == 'xiaoshoumingxi'){
            //     return;
            // }else{
            //     this.wlqdtabelShownew = true;
            //     this.$nextTick(() => {
            //         this.$refs.wlqdtabel.openBox(row.id, row)
            //     })
            // }
        },
        // 双击
        async handleRowDblClick(row){
            // 将选中的行的id赋值给this.boxid
            this.boxid = row.id;
            if(this.keyName == 'xiaoshoumingxi'){
                return;
            }else{
                if(this.keyName == 'shengchandan'){
                    const data = await crudModuleFindApi(this.keyName, row.id)
                    this.addDrawerShownew = true;
                    this.$nextTick(() => {
                       let resdatas = data.data || '';
                       this.$refs.addDrawernew.openBox(row.id, resdatas, 0)
                    })
                }else{
                    this.wlqdtabelShownew = true;
                    this.$nextTick(() => {
                        this.$refs.wlqdtabel.openBox(row.id, row)
                    })
                }
            }
        },
        async onCheck(row){
            this.boxid = row.id;
            if(this.keyName == 'shengchandan'){
                const data = await crudModuleFindApi(this.keyName, row.id)
                this.addDrawerShownew = true;
                this.$nextTick(() => {
                    let resdatas = data.data || '';
                    this.$refs.addDrawernew.openBox(row.id, resdatas, 0)
                })
            }else{
                this.wlqdtabelShownew = true;
                this.$nextTick(() => {
                    this.$refs.wlqdtabel.openBox(row.id, row)
                })
            }
        },
       
        
        async editRow(item, index=0) {
            // this.addDrawerShow = true
            const data = await crudModuleFindApi(this.keyName, item.id)
            this.addDrawerShownew = true;
            this.$nextTick(() => {
              let resdatas = data.data || '';
              this.$refs.addDrawernew.openBox(item.id, resdatas, index)
            })
      
        },
        // 根据数量和单价计算金额
        handlerMoneyjs(event,index, row){
            if(event){
                let sumcount = Number(event) + Number(row.shuliang)
                row.shengchanshu = sumcount;
            }else{
                row.shengchanshu = Number(row.shuliang);
            }
            this.$set(this.tableData, index, row)
        },
        // 对数据进行处理 返回名称
        handlerReplacexiegan(val, fieldname){
            if(val){
                if(val.includes('/')){
                    let name = val.replace(/\//g, '')
                    let didList = this.zidiangData[fieldname];
                    if(didList && didList.length > 0){
                        for(let i=0;i< didList.length;i++){
                            if(name == didList[i].name || name == didList[i].value){
                                return didList[i].name;
                            }
                        }
                    }
                    return name;
                }else{
                    
                    return val;
                }
            }else{
                return ''
            }
        },
        handlerfilterk(name){
           if(name){
              if(name == '0000-00-00 00:00:00'){
                 return ''
              }else{
                 return name;
              }
           }else{
              return ''
           }
        },
        // 对字典数据进行出来返回value值
        handlerReplacexieganVal(val, didList){
            if(val){  
                for(let i=0;i< didList.length;i++){
                    if(val == didList[i].name || val == didList[i].value){
                        return [didList[i].value];
                    }
                }
            }
            return '';
        },
         // 对实体表数据进行出来返回value值
         handlerbaseValobj(val, didList){
            if(val){  
                for(let i=0;i< didList.length;i++){
                    if(val == didList[i].id){
                        return {id: didList[i].id, name: didList[i].zhongwenmiaoshu};
                    }
                }
            }
            return '';
        },
        // 实体表对数据进行处理返回name
        handleraccociation(val, fieldname){
            if(val){
                let didList = this.zidiangData[fieldname];
                if(didList && didList.length>0 ){
                    for(let i=0;i< didList.length;i++){
                        if(fieldname == 'kehao'){
                            if(val == didList[i].kehao){
                               return didList[i].id;
                            } 
                        }else{
                          if(val == didList[i].leibiedaima){
                            return didList[i].zhongwenmiaoshu;
                          }  
                    }   }
                }
                return val;
            }else{
                return ''
            }
        },
        handlerValue(val){
            if(val){
                if(Array.isArray(val)){
                    return val.join(',')
                }else if(this.isObject(val)){
                    return val.name || '';
                }else{
                    return val;
                }
            }else{
                return ''
            }
        },
        // 判断是否是object对象
        isObject(value) {
            return value !== null && Object.prototype.toString.call(value) === '[object Object]';
        },
        // 显示tablecolumn宽度
        handelrWidth(item){
            let textname = ['gongsidaima', 'item_sn', 'wuliaozhongwenmiaoshu', 'item_depc'];
            let textname2 = ['kehaomingcheng', 'shuliang', 'mianfeishu', 'choudanshu', 'shengchanshu']
            let textname3 = ['danwei', 'laiyuan','zhuangtai', 'choudanbeizhu']
            let texttime = ['updated_at', 'created_at']
            if(textname.includes(item.field_name_en)){
                return '220px';
            }else if(textname2.includes(item.field_name_en)){
                return '60px'
            }else if(textname3.includes(item.field_name_en)){
                return '90px'
            }else if(texttime.includes(item.field_name_en)){
                return '150px'
            }else{
                return '120px'
            }
        },
        handlerDisabel(filedname){
            let textdata = ['gongsidaima', 'danwei', 'danjuleixing']
            if(textdata.includes(filedname)){
                return true;
            }
            return false;
        },
        handlerDisabelval(val, fieldname){
            let name = '';
            if(val){
                let didList = this.zidiangData[fieldname];
                if(didList && didList.length>0 ){
                    for(let i=0;i< didList.length;i++){
                        if(val == didList[i].name || val == didList[i].value){
                            return didList[i].name;
                        }
                    }
                }
                return val;
            }
            return name;
        }



    }
}
</script>

<style lang="scss" scoped>

/deep/ .draggable-table .el-textarea__inner{
  border:none!important;
}
/deep/ .draggable-table .el-input__inner{
  border:none!important;
  padding: 0 2px!important;
}
/* select 上拉箭头 */
/deep/ .draggable-table .el-icon-arrow-up:before{
   content:''
}
/deep/ .draggable-table .el-input--medium .el-input__icon.el-icon-circle-close{
   line-height:28px!important;
}
/deep/ .draggable-table .el-input--suffix .el-input__inner{
   padding: 0 2px!important;
}
/deep/ .draggable-table .el-input__icon{
    width:16px;
}
/deep/ .draggable-table .el-input--medium .el-input__icon{
    line-height:28px;
}
/deep/ .el-table .cell{
  line-height: 20px;
}

.drag-handle {
  cursor: move;
}

.drag-wrapper {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.drag-wrapper > * {
  pointer-events: all;
}

.drag-item {
  height: 48px; /* 与行高一致 */
}

.ghost {
  opacity: 0.5;
  background: #c8ebfb;
}

.flip-list-move {
  transition: transform 0.5s;
}
.divBox {
    height: 100%;
}

.mt16 {
    margin-top: 7px;
}

.img {
    display: block;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    margin-right: 4px;
}

.prompt-bag {
    background-color: #edf5ff;
    font-family: PingFang SC, PingFang SC;
    font-weight: 400;
    font-size: 12px;
    color: #606266;
}

/deep/.el-button--small {
    font-size: 13px;
}

.el-icon-question {
    cursor: pointer;
    color: #1890ff;
    font-size: 15px;
}

/deep/ .el-card__body {
    padding: 0 20px;
}

.iconzhuyaobumen {
    color: #ff9900;
}

.boder-left {
    min-height: calc(100vh - 77px);
    border-left: 1px solid #eeeeee;
}

.p20 {
    padding: 20px 0;
}

.table-container {
    margin-top: 10px;
}
/* 如果需要拖拽手柄 */
.drag-handle {
  cursor: move;
}
</style>